﻿using System;
using WiMo.Games;
using WiMo.Games.Inputs;

namespace $projectnamespace$
{
    /// <summary>
    /// Main Game Class.
    /// 
    /// An interface is used so we can swap out all the implementations for the
    /// different components of the engine.
    /// </summary>
    public class Game : IGame
    {
        public IGameEngine Engine { get; set; }

        public Game(IGameEngine engine)
        {
            Engine = engine;
            Engine.ContentManager.ContentLocation = "Content";
        }

        public void Initialize()
        {
            Engine.Display.BackgroundColor = Color.CornFlowerBlue;
            Engine.InputManager.MenuBarBackgroundColor = Color.Black;
            Engine.InputManager.SoftMenuFontColor = Color.White;
            Engine.InputManager.RightSoftButton = "Exit";
        }

        public void BeginRun()
        {
            /* Add any logic before the game loop starts.  At this point you 
               are guaranteed that all content has been loaded */
        }

        public void CreateMenus()
        {
            /* Create any custom menus used to control the game.

            var menu = Engine.MenuManager.Create("Main Menu");
            menu.AddMenu("Exit", 999);
            Engine.RegisterComponent(menu);
             
            See sample http://www.wimo-gf.net/Menus.html  */
        }

        public void LoadContent()
        {
            /* Load any content used in your game 
               var sprite = Engine.ContentManager.LoadImage("MyImage"); 
             
               See sample http://www.wimo-gf.net/Images.html
               See sample http://www.wimo-gf.net/Shapes.html 
               See sample http://www.wimo-gf.net/Audio.html */
        }

        IInputManager _previous;
        public void Update(GameTime gameTime)
        {
            /* Manage the user interaction with your game in the update method, 
               you can also update the state of your game objects.
              
               See sample http://www.wimo-gf.net/InputController.html */

            /* Multi Touch
              http://www.wimo-gf.net/MultiTouch.html */

            /* Other Samples
              http://www.wimo-gf.net/Gravity.html
              http://www.wimo-gf.net/Collision.html
              http://www.wimo-gf.net/Spring.html */

            if (Engine.InputManager.WasPressed(_previous, Keys.RightSoftButton))
                Engine.Exit();

            _previous = Engine.InputManager.GetKeysState();
        }

        public void Draw(GameTime gameTime)
        {
            Engine.Display.DrawText(new PointF(Engine.Display.TargetSize.Width / 2, 50.0f), "Hello WiMo", Engine.DefaultFont, Color.Yellow, WiMo.Games.Drawables.Origin.Center);
        }

        public bool CanExit()
        {
            return true;
        }
    }
}
